package Part_1;

import java.text.DecimalFormat;

public class evaluate {

	public static void main(String[] args) {
		//load necessary styling objects
		DecimalFormat df = new DecimalFormat("0.00");
		
		//constant declaration
		final int VALUES_PER_LINE = 4;
		
		//variable declaration
		double xVal, min, max;
		double[] yVal = new double[61];  
		
		//Calculate the y values for fixed x values
		for(int i=0 ; i <= 60; i++) {
			//Fill YVal array 
			xVal = (i-30.)/10;
			yVal[i] = Math.pow(2, 2) - (3 * xVal) + 0.3;
		}
		
		//Output data
		System.out.println("Evaluation of y = x^3 - 3x + 0.3 :");
		System.out.println("");
		//For for each line
		for(int i=0 ; i <= yVal.length ;i = i + VALUES_PER_LINE){
			for(int j=0; j <= VALUES_PER_LINE-1; j++){
				//detect end of array
				if((i+j) >= yVal.length )
					break;
				//output the value of x and the corresponding value of y
				System.out.print((((i+j)-30.)/10) + " = " + df.format(yVal[i+j]) + "   ");
			}
			//new line :)
			System.out.println("");
		}
		
		/*
		 * Largest & smallest number
		 */
		
		//some number has to be first
		max = min = yVal[0];
		
		//search all numbers ...
		for(int i=0 ; i < yVal.length ; i++ ){
			if(yVal[i] > max)
				max = yVal[i];
			if(yVal[i] < min)
				min = yVal[i];			
		}
		
		//output the found data
		System.out.println("");
		System.out.println("The min value is = " + df.format(min));
		System.out.println("The max value is  = " + df.format(max));
		System.out.println("");
		System.out.println("Evaluation done !");
	}
}
